// pages/get_ticket/index.js
import { getUserOrderDetail ,refund} from '../../api/order'
import { getSettingInfo } from '../../api/common'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    msg:''//温馨提醒
  },
  getTextarea(e){
    this.setData({ textareaValue: e.detail.value.replace(/(^\s*)|(\s*$)/g, "")})
  },
  toRefund(){
    this.setData({ showRefund: !this.data.showRefund})
  },
   //退款接口
   _refund(){
    let orderId = this.data.order.orderId//订单主键
    let refundRemark = this.data.textareaValue//退款说明
    let obj={
      orderId:orderId,
      refundRemark:refundRemark
    }
    refund(obj).then(res=>{
      wx.showModal({
        title: '申请' + (res.code == 0?'成功':'失败'),
        content: res.msg,
        showCancel: false,//是否显示取消按钮
        confirmText: "确定",//默认是“确定”
        confirmColor: '#000000',//确定文字的颜色
        success: function (res) {
          if (res.confirm) {
            setTimeout(() => {
              wx.navigateBack(1)
            }, res.code == 0?1000:3000);
          }
        }
      })
    })
  },
  send(){
    if(this.data.textareaValue){
      this._refund()
    }else{
      wx.showToast({
        title: '请填写退款原因',
        icon:'none'
      })
    }
  },
  //重新报名
  anew(){
    wx.navigateTo({
      url: '/pages/competition_detail/index?id='+this.data.order.matchId,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._getUserOrderDetail(options.orderid)
  },
  _getUserOrderDetail(orderid){
    getUserOrderDetail(orderid).then(res=>{
      this.setData({...res.data})
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    //获取温馨提醒
    this._getSettingInfo()
  },
  _getSettingInfo(){
    getSettingInfo().then(res=>{
      this.setData({
        msg:res.data.warmTip
      })
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this._getUserOrderDetail(this.data.order.orderId)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onUnload:function(){
    //如果是订单列表进来，正常返回，如果是下单流程进入订单详情，则返回到详情页面
    var pages=getCurrentPages();//页面指针数组
    var prepage=pages[pages.length-2];//上一页面指针
    if(prepage.route=="pages/order/index"){

    }else{
      wx.navigateBack({
        delta: 3
      })
    }
  }
})